package com.yanxml.springboot.core.listener.custom.business_event.publisher;

import com.yanxml.springboot.core.listener.custom.business_event.event.MyCustomApplicationEvent;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyEventPublisher implements ApplicationEventPublisher, ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void publishCustomEvent(MyCustomApplicationEvent event){
        applicationContext.publishEvent(event);
    }

    @Override
    public void publishEvent(Object event) {
        applicationContext.publishEvent(event);
    }
}
